import java.io.IOException;
import moos.ssds.jms.PublisherComponent;
import moos.ssds.transmogrify.SSDSDevicePacket;
/**
* <p>
* Publish instrument data records to the SSDS database. The client must provide
* SSDS device ID, timeStamp, sequence number, and payload.
* </p>
* <hr>
*
* @author : $Author: mccann $
* @version : $Revision: 1.17.2.7 $
* <hr>
* <p>
* <font size="-1" color="#336699"><a href="http:> The
* Monterey Bay Aquarium Research Institute (MBARI)</a> provides this
* documentation and code "as is", with no warranty, express
* or implied, of its quality or consistency. It is provided without
* support and without obligation on the part of MBARI to assist in its
* use, correction, modification, or enhancement. This information
* should not be published or distributed to third parties without
* specific written permission from MBARI.</font>
* </p>
* <br>
* <font size="-1" color="#336699">Copyright 2008 MBARI.<br>
* MBARI Proprietary Information. All rights reserved.</font><br>
* <hr>
* <br>
*/
/**
* @author mccann
*
*/
public class SsdsPublisher {
/**
* Publish data record from an instrument to SSDS
*
* @param deviceID
* is the SSDS Device ID for the instrument that produces the data in payload
* @param epochMilliseconds
* time of payload sample in milliseconds since 1/1/1970 0000 GMT
* @param sequenceNumber
* an incrementing number for each packet
* @param payload
* data from instrument
*/
public static void publish(long deviceID, long epochMilliseconds, long sequenceNumber,
String payload) {
PublisherComponent pc = new PublisherComponent();
SSDSDevicePacket packetToSend = new SSDSDevicePacket(deviceID, payload
.getBytes().length);
packetToSend.setPacketType(1);
packetToSend.setSystemTime(epochMilliseconds);
packetToSend.setPlatformID(0);
packetToSend.setMetadataRef(0);
packetToSend.setSequenceNo(sequenceNumber);
packetToSend.setDataBuffer(payload.getBytes());
packetToSend.setRecordType(1);
try {
pc.publishBytes(SSDSDevicePacket
.convertToPublishableByteArray(packetToSend));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Test of SsdsPublisher.publish()
*
* @param args
* No arguments are taken. Test values hard coded.
*/
public static void main(String[] args) {
/*
* Example packet for EITS instrument
*/
long eitsDeviceID = 1696; long sampleTime = 1228431283209L; long sampleSequenceNumber = 1;
String samplePayload = "12.2, 4.3, 768.2, 2.3, 1.2, 0.2";
SsdsPublisher.publish(eitsDeviceID, sampleTime, sampleSequenceNumber, samplePayload);
}
}